<?php
    require_once 'classes/Login.php';
    require_once 'classes/JobPost.php';
    $Login = new Login;
    $JobPost = new JobPost;
    include 'includes/header.inc.php';
	$lastSearch = $JobPost->saveLastSearch($_GET['country'],$_GET['state1'],$_GET['city'],$_GET['jobCat']);
    $searchPosts = $JobPost->getSearchPosts($_GET['country'], $_GET['state1'], $_GET['city'], $_GET['jobCat']);
    if(!empty($searchPosts))
    {
        //var_dump($searchPosts);
        for($i=0;$i<count($searchPosts);$i++)
        {
            //echo $searchPosts[$i]['id'];
            //echo '<br/>';
            $searchPosts[$i]['locations'] = $JobPost->getLocations($searchPosts[$i]['id']);
        }
    ?>
    <table class="postingsTable">
        <thead>
            <tr>
                <th scope="col" id="postDate">Date</th>
                <th scope="col" id="postTitle">Title</th>
                <th scope="col" id="locations">Locations</th>
                <th scope="col" id="catID">Category</th>
            </tr>
        </thead>
        <tbody>
<?php
    for($i=0;$i<count($searchPosts);$i++)
    {
        $date = strtotime($searchPosts[$i]['postDate']);
        echo '<tr>
                <td class="jobDate">'.date("m/d/y", $date).'</td>
                <td class="jobTitle"><a href="/sandbox1/viewJobPostBasic.php?jobID='.$searchPosts[$i]['id'].'">'.$searchPosts[$i]['title'].'</a></td>
                <td class="jobLocations">';
        //var_dump($expiredFlag);
        for($n=0;$n<count($searchPosts[$i]['locations']);$n++)
        {
               echo $searchPosts[$i]['locations'][$n][1];
               echo ', ';
               echo $JobPost->getStateName($searchPosts[$i]['locations'][$n][2]);
               echo '<br/>';
        }
        echo    '</td>
                <td class="jobTitle">'.$JobPost->getCategoryName($searchPosts[$i]['catID']).'</td>
            </tr>';
    }
    ?>
        </tbody>
    </table>
<?php
    }
    else
    {
?>
<div id="noResults">No search results for your query.</div>
<?php
    }
    include 'includes/footer.inc.php';
?>